angular.module('zqh.controller', [])

    .controller('LoginCtrl', function ($scope, $ionicLoading, $location, Customer, Storage) {
        var storageKey = 'user';
        //1 用户登陆
        $scope.user = {
            mobile: '',
            password: ''
        }
        $scope.signIn = function () {
            if (Customer.checkLogin($scope.user.mobile, $scope.user.password)) {
                Customer.login($scope.user.mobile, $scope.user.password);
            }
        }

        $scope.$on('Customer.loginUpdated', function () {
            var userRel = Customer.getCurrentUser();
            if (userRel.code == 0) {
                $ionicLoading.show({
                    noBackdrop: true,
                    template: '登录成功',
                    duration: 1500
                });
                $location.path('/error');
                $location.replace();
            }
        });
    })

    .controller('ErrorCtrl', function ($scope, ErrorFactroy, Storage) {
    })

    .controller('FinderCtrl', function ($scope, $location,$state,Storage, $ionicLoading, FinderFactroy) {
        FinderFactroy.getData();
        $scope.goTo = function (item) {
              window.location.href = 'blank.html?url='+item.url;
            // console.log(url);
            // location.href=url;
            // Storage.set("channelUrl", item.url);
            // $state.go('blank', {channelId: item.id});
            // $location.path('/blank');
            // $location.replace();

        }

        $scope.$on('FinderFactroy.finder', function () {
            var myData = FinderFactroy.getDaoliuData();
            if (myData.code == 0) {
                //Storage.set("channelId",myData.id);
                $scope.daoliudata = myData;
                $location.path('/finder');
                $location.replace();
            }
        })
    })
